$(function () {
	vm.zhidaoId = getQueryString("id");
	vm.mentorId = getQueryString("mentorId");
	vm.getStudentList(vm.mentorId);
});

var vm = new Vue({
	el:'#mapp',
	data:{
		title: "",
		zhidaoId: "",
		mentorId: "",
		//项目进展
		bsnXmjz: {},
		bsnStudentList: {},
		pageParams: {
			limit: "100",
			page: "1"
		},
		selectedStudents: new Map()
	},
	methods: {
		getStudentList: function(mentorId){
			vm.pageParams.mentorId = vm.mentorId;			
			$.ajax({
				type: "POST",
			    url: ajaxServerUrlG("bsnstudent/listByMentor"),
                contentType: "application/json",
			    data: JSON.stringify(vm.pageParams),
			    success: function(r){
			    	if(r.code === 0){
						vm.bsnStudentList = r.page.list;
					}else{
						alert(r.msg);
					}
				}
			});
		},
		gotoEdit: function(id) {
			location.href = "msStudentInfoEdit.html?id=" + id + "&title=学生信息";
		},
		save: function() {
			if (vm.selectedStudents.size == 0) return;
			params = {
				zhidaoId: vm.zhidaoId,
				mentorId: vm.mentorId,
				students: []
			};
			vm.selectedStudents.forEach(function (value, key, map) {
				params.students.push(value);
			});
			$.ajax({
				type: "POST",
			    url: ajaxServerUrlG("bsngoutongzhidaorelation/save"),
                contentType: "application/json",
			    data: JSON.stringify(params),
			    success: function(r){
			    	if(r.code === 0){
						alert("保存成功");
					}else{
						alert(r.msg);
					}
				}
			});	
		},
		select: function(e, studentId) {
			if (e.currentTarget.checked) {
				vm.selectedStudents.set(studentId, studentId);
			} else {
				vm.selectedStudents.delete(studentId);
			}
		}
	},
	filters: {
		/*过滤并替换头像 */
		imgFilter: function (imgUrl, xingb) {
			// console.log(imgUrl);
			if (StringUtils.isNotEmpty(imgUrl)) {
				return imgUrl;
			}
			if (xingb == "男") {
				return "images/man@2x.png";
			} else {
				return "images/woman@2x.png";
			}
		}
	}
});